import pymongo
import json
import datetime
# MONGO_URI = "mongodb://localhost:27017/"

MONGO_URI = "mongodb://47.93.220.108:27017/"
movieIndfo = pymongo.MongoClient(MONGO_URI)['movie']['movieInfo'].find()
data = {}
for x in movieIndfo:
    kind = x.get("movie_class").split(',')
    name = x.get("movie_name" )
    num =  pymongo.MongoClient(MONGO_URI)['movie']['movieComment'].find({"movie_name":name})[0].get("sentiment")
    num = sum(num)
    for j in kind:
        if j in data:
            data[j] += num
        else:
            data[j] = num
    print(data)
print(datetime.datetime.now())
with open('./emotion.json','w',encoding='utf-8') as f:
    f.write(json.dumps(data,ensure_ascii=False))
